# Maintainer: Simon Kissane <skissane@gmail.com>

_realname=mtools
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.0.43
pkgrel=1
pkgdesc="collection of utilities to access FAT filesystems without mounting them"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
url="https://www.gnu.org/software/mtools"
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.lz{,.sig}
        "0001-nl_langinfo.patch")
sha256sums=('997ffe4125a19de1fd433ed63f128f7d54bc1a5915f3cdb36da6491ef917f217'
            'SKIP'
            '999661ece6c41bd0b316426bae7df585972037db0a4de491786f477646749eb6')
validpgpkeys=('51A23D9D7C4DF41AA48FA893E99CF5537790B839')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  patch -p1 -i $srcdir/0001-nl_langinfo.patch
  autoreconf -fiv
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}"

  make USERLDLIBS=-"liconv"
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/README"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
